<template>
    <div class="resultform">
        <h4 class="no-mr" v-if="searchResult.searchID">简历搜索结果</h4>
        <el-table
                :data="resultData"
                stripe
                style="width: 100%;">
            <el-table-column
                    prop="position"
                    label="职位名称"
                    align="center"
                    header-align="center"
            >
            </el-table-column>

            <el-table-column
                    label="发布时间"
                    align="center"
                    header-align="center"
                    sortable
            >
                <template slot-scope="scope">
                    <i class="el-icon-time"></i>
                    <span>{{ scope.row.pubtime }}</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="人才姓名"
                    align="center"
                    header-align="center">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleShow(scope.$index, scope.row)">
                        {{scope.row.name}}
                    </el-button>
                </template>

            </el-table-column>

            <el-table-column
                    prop="gender"
                    label="性别"
                    align="center"
                    header-align="center">
                <template slot-scope="scope">
                    <el-tag
                            :type="getGender(scope.row.gender).style"
                            disable-transitions>{{getGender(scope.row.gender).text}}
                    </el-tag>
                </template>
            </el-table-column>

            <el-table-column
                    prop="mobile"
                    label="人才联系方式"
                    align="center"
                    header-align="center">
            </el-table-column>

            <el-table-column
                    prop="bole"
                    label="所属伯乐"
                    align="center"
                    header-align="center">
            </el-table-column>

            <el-table-column
                    prop="status"
                    label="状态"
                    align="center"
                    header-align="center">
                <template slot-scope="scope">
                    <el-tag
                            :type="statusList[scope.row.status].style"
                            disable-transitions>{{statusList[scope.row.status].name}}
                    </el-tag>
                </template>
            </el-table-column>

            <el-table-column label="操作"
                             align="center"
                             header-align="center"
                             v-if=isShowModify>
                <template slot-scope="scope">
                    <el-button
                            type="warning"
                            @click="handleEdit(scope.$index, scope.row)">修改状态
                    </el-button>
                </template>
            </el-table-column>
            <el-table-column label="操作"
                             align="center"
                             header-align="center">
                <template slot-scope="scope">
                    <el-button
                            type="success"
                            @click="showResumeFile(scope.$index, scope.row)">查看简历或简介
                    </el-button>
                </template>
            </el-table-column>

        </el-table>
        <el-dialog title="更新简历状态" :visible.sync="dialogFormVisible">
            <el-form ref="form" status-icon :model="formData" label-width="450px" id="update_status">
                <el-form-item label="简历状态" prop="status">
                    <el-select v-model="formData.status" placeholder="简历状态">
                        <el-option label="未审核" value="0"></el-option>
                        <el-option label="顾问淘汰" value="1"></el-option>
                        <el-option label="已推荐" value="2"></el-option>
                        <el-option label="已面试" value="3"></el-option>
                        <el-option label="已发Offer" value="4"></el-option>
                        <el-option label="已入职" value="5"></el-option>
                        <el-option label="客户淘汰" value="6"></el-option>
                        <el-option label="已结算" value="7"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-col>
                        <el-button type="primary" @click="updateStatus()">更新状态</el-button>
                    </el-col>
                </el-form-item>
            </el-form>
        </el-dialog>
        <el-dialog title="查看人才信息" :visible.sync="dialogFormVisible2">
            <el-table
                    :data="tableData"
                    stripe
                    style="width: 100%;">
                <el-table-column
                        prop="name"
                        label="姓名"
                        align="center"
                        header-align="center">
                </el-table-column>
                <el-table-column
                        prop="liveCity"
                        label="人才所在城市"
                        align="center"
                        header-align="center">
                </el-table-column>
                <el-table-column
                        prop="mobile"
                        label="联系方式"
                        align="center"
                        header-align="center">
                </el-table-column>
                <el-table-column
                        prop="email"
                        label="邮箱"
                        align="center"
                        header-align="center">
                </el-table-column>
                <el-table-column
                        prop="area"
                        label="期望行业"
                        align="center"
                        header-align="center">
                </el-table-column>
                <el-table-column
                        prop="position"
                        label="期望职位"
                        align="center"
                        header-align="center">
                </el-table-column>
            </el-table>
        </el-dialog>
        <br/>
        <el-row type="flex" justify="center">
            <el-pagination
                    style="align-self:center"
                    background
                    layout="prev, pager, next"
                    :page-count="pages"
                    @current-change="changePage">
            </el-pagination>
        </el-row>
    </div>

    <!--<el-table-->
        <!--:data=""-->
        <!--stripe-->
        <!--style="width: 100%;">-->

    <!--</el-table>-->
</template>
<script>
    import Config from '@myconfig/config.min'
    import axios from 'axios'

    export default {
        name: 'result-form',
        data() {
            return {
                currentPage: 1,
                pages: 1,
                resultData: [],
                statusList: [
                    {name: '未审核', style: ''},
                    {name: '顾问淘汰', style: ''},
                    {name: '已推荐', style: ''},
                    {name: '已面试', style: ''},
                    {name: '已发Offer', style: 'warning'},
                    {name: '已入职', style: 'info'},
                    {name: '客户淘汰', style: 'danger'},
                    {name: '已结算', style: 'success'},
                ],
                dialogFormVisible: false,
                formData: {
                    prid: '',
                    status: ''
                },
                dialogFormVisible2: false,
                tableData:[{
                    name: '',
                    liveCity: '',
                    mobile: '',
                    position: '',
                    email: '',
                    area: ''
                }],
                isShowModify: true,
                param1: '',
                param2: ''
            }
        },
        props: {
            searchResult: {
                type: Object,
                require: false,
            },
        },
        created() {
            this.getData();
            this.initModify();
        },
        // watch:{
        //   'searchResult.searchID':function(){
        //     console.log('id change')
        //     this.getData()
        //   }
        // },
        methods: {
            getGender(gender) {
                switch (gender) {
                    case 0:
                        return {
                            style: 'success',
                            text: '男'
                        }
                    case 1:
                        return {
                            style: 'warning',
                            text: '女'
                        }
                }
            },
            getData() {
                console.log(this.$route.params.positionParam1 );
                if (this.$route.params.positionParam1 === undefined) {
                    this.param1 = "";
                    this.param2 = "";
                } else {
                    this.param1 = this.$route.params.positionParam1;
                    this.param2 = this.$route.params.positionParam2;
                }
                this.$http
                    .get(
                        Config.baseUrl + "/api/lietou/" + this.param1 + "resumes/" + this.param2 + this.currentPage
                    )
                    .then(function (rsp) {
                        if (
                            rsp.data.pageNum == this.currentPage
                        ) {
                            this.resultData = rsp.data.list;
                            this.pages = rsp.data.pages;
                        }
                    });
            },
            getResumeData(resumeId) {
                let _this = this;
                axios({
                    method: 'get',
                    url: Config.baseUrl + "/api/resume/"+ resumeId,
                }).then(function (response) {
                    if (response.data.code != 1) {

                    } else {
                        _this.tableData[0].name = response.data.data.name;
                        _this.tableData[0].liveCity = response.data.data.liveCity;
                        _this.tableData[0].position = response.data.data.position;
                        _this.tableData[0].mobile = response.data.data.mobile;
                        _this.tableData[0].email = response.data.data.email;
                        _this.tableData[0].area = response.data.data.area;
                    }
                })
            },
            changePage(value) {
                this.currentPage = value;
                this.getData()
            },
            handleEdit(index, row) {
                this.dialogFormVisible = true;
                this.formData.prid = row.prid;
            },
            handleShow(index, row) {
                this.getResumeData(row.resumeId);
                this.dialogFormVisible2 = true;
            },
            updateStatus() {
                let _this = this;
                axios({
                    method: 'post',
                    url: Config.baseUrl + "/api/resume/status",
                    params: {
                        prid: _this.formData.prid,
                        status: _this.formData.status
                    },
                }).then(function (response) {
                    if (response.data.code != 1) {
                        _this.$notify({
                            title: '更新失败',
                            message: response.data.msg,
                            type: 'error'
                        });
                    } else {
                        _this.$notify({
                            title: '更新成功',
                            message: response.data.data,
                            type: 'success'
                        });
                        _this.getData();
                    }
                })
            },
            showResumeFile(index, row) {
                if (row.resumeFilePath === '' || row.resumeFilePath == null) {
                    this.$alert(row.avatar, '伯乐暂未上传简历，以下为人才简介', {
                        confirmButtonText: '确定',
                    });
                }
                else {
                    window.open(Config.baseUrl+ "/api/resume/file/"+row.resumeId);
                }
            },
            initModify() {
                let _this = this;
                axios({
                    method: 'get',
                    url: Config.baseUrl + "/api/user/now",
                }).then(function (response) {
                    if (response.data.code == 1) {
                        console.log(response.data.data.role);
                        if (response.data.data.role == 3) {
                            _this.isShowModify = false
                        }
                        else {

                        }
                    }
                })
            },
            afterRoute() {
                console.log("1111111111");
                console.log("Routed!"+this.$route.params.position);
                let routerParams = this.$route.params.position;
                this.positionParam = 'position/';
                this.pidParam = routerParams + '/';
            }
        },
    }
</script>

<style>
    .resultform h4 {
        margin: 0;
        padding: 10px 20px 0 20px;

        font-size: 14px;
    }

    .no-mr {
        margin: 0
    }

    .el-table .warning-row {
        background: #E6A23C;
    }

    .el-table .success-row {
        background: #67C23A;
    }

    .el-table .danger-row {
        background: #F56C6C;
    }

    .el-table .primary-row {
        background: #409EFF;
    }

    .el-table .info-row {
        background: #909399;
    }
</style>
